function Fireice_pref() 
{
	/* Add initialization code here */
	var row_no=1;
	var value;
	var server_add,server_port,server_pass,server_mount,server_default;
}

Fireice_pref.prototype = {
		fetch:function()
		{
	var row_no=1;		
	var firefoggId = "fireice@abhinav.chittora";
	var em = Components.classes["@mozilla.org/extensions/manager;1"]
	                            .getService(Components.interfaces.nsIExtensionManager);
	var xulRuntime = Components.classes["@mozilla.org/xre/app-info;1"]
	                                    .getService(Components.interfaces.nsIXULRuntime);
	var exec_name = "content";
	var cmd = em.getInstallLocation(firefoggId).getItemFile(firefoggId, exec_name);
	cmd.append("fireice.sqlite");
	var storageService = Components.classes["@mozilla.org/storage/service;1"]
	                                        .getService(Components.interfaces.mozIStorageService);
	var mDBConn = storageService.openDatabase(cmd); 
	var statement = mDBConn.createStatement("SELECT * FROM fireice_server");
	try 
	{	
		statement.executeAsync(
				{
					handleResult: function(aResultSet) 
					{
					for (let row = aResultSet.getNextRow();	row; row = aResultSet.getNextRow()) 
					{
						this.server_add = row.getResultByName("server_add");
						this.server_port = row.getResultByName("port");
						this.server_pass = row.getResultByName("password");
						this.server_mount = row.getResultByName("mount_point");
						this.server_default = row.getResultByName("isdefault");
						//alert(this.server_add);
						if(this.server_add=="" || this.server_port=="" || this.server_pass=="" || this.server_mount=="")
						{
							alert("Error in Database");
						}
						else
						{
							var linkElement = document.createElement("treeitem"); 
							linkElement.setAttribute("id","treeitem"+row_no);

							var l = document.createElement("treerow"); 
							l.setAttribute("id","treerow"+row_no);

							var c1= document.createElement("treecell");
							c1.setAttribute("label",this.server_add);

							var c2= document.createElement("treecell");
							c2.setAttribute("label",this.server_port);

							var c3= document.createElement("treecell");
							c3.setAttribute("label",this.server_pass);

							var c4= document.createElement("treecell");
							c4.setAttribute("label",this.server_mount);

							var c5= document.createElement("treecell");
							c5.setAttribute("label",this.server_default);

							document.getElementById('server-value').appendChild(linkElement);
							document.getElementById('treeitem'+row_no).appendChild(l);
							document.getElementById('treerow'+row_no).appendChild(c1);
							document.getElementById('treerow'+row_no).appendChild(c2);
							document.getElementById('treerow'+row_no).appendChild(c3);
							document.getElementById('treerow'+row_no).appendChild(c4);
							document.getElementById('treerow'+row_no).appendChild(c5);
						}
						row_no+=1;
					}
					},
					handleError: function(aError) 
					{
						print("Error: " + aError.message);
					},
					handleCompletion: function(aReason) 
					{
						if (aReason != Components.interfaces.mozIStorageStatementCallback.REASON_FINISHED)
							print("Query canceled or aborted!");
					}
				});
	}
	finally 
	{
		statement.reset();
	}
	this.row_no= row_no;
		},
		add_server:function()
		{
			var row_no=this.row_no;
			row_no=row_no+1;
			this.server_add = document.getElementById('stream-server-address').value;
			this.server_port = document.getElementById('stream-port-no').value;
			this.server_pass = document.getElementById('stream-password').value;
			this.server_mount = document.getElementById('stream-mount-point').value;
			this.server_default = document.getElementById("stream-default").checked;
			var firefoggId = "fireice@abhinav.chittora";
			var em = Components.classes["@mozilla.org/extensions/manager;1"]
			                            .getService(Components.interfaces.nsIExtensionManager);
			var xulRuntime = Components.classes["@mozilla.org/xre/app-info;1"]
			                                    .getService(Components.interfaces.nsIXULRuntime);
			var exec_name = "content";
			var cmd = em.getInstallLocation(firefoggId).getItemFile(firefoggId, exec_name);
			cmd.append("fireice.sqlite");
			var storageService = Components.classes["@mozilla.org/storage/service;1"]
			                                        .getService(Components.interfaces.mozIStorageService);
			var mDBConn = storageService.openDatabase(cmd); 
			if(this.server_add=="" || this.server_port=="" || this.server_pass=="" || this.server_mount=="")
			{
				alert("Enter all the value");
			}
			else
			{
				if(this.server_default)
				{
					var q= "UPDATE fireice_server SET 'isdefault'='false'";
					mDBConn.executeSimpleSQL(q);
				}
				var query = "INSERT INTO fireice_server ('server_add','password','mount_point','port','isdefault') VALUES ('"+this.server_add+"','"+this.server_pass+"','"+this.server_mount+"','"+this.server_port+"','"+this.server_default+"')";
				mDBConn.executeSimpleSQL(query);

				var linkElement = document.createElement("treeitem"); 
				linkElement.setAttribute("id","treeitem"+row_no);

				var l = document.createElement("treerow"); 
				l.setAttribute("id","treerow"+row_no);

				var c1= document.createElement("treecell");
				c1.setAttribute("label",this.server_add);

				var c2= document.createElement("treecell");
				c2.setAttribute("label",this.server_port);

				var c3= document.createElement("treecell");
				c3.setAttribute("label",this.server_pass);

				var c4= document.createElement("treecell");
				c4.setAttribute("label",this.server_mount);

				var c5= document.createElement("treecell");
				c5.setAttribute("label",this.server_default);

				document.getElementById('server-value').appendChild(linkElement);
				document.getElementById('treeitem'+row_no).appendChild(l);
				document.getElementById('treerow'+row_no).appendChild(c1);
				document.getElementById('treerow'+row_no).appendChild(c2);
				document.getElementById('treerow'+row_no).appendChild(c3);
				document.getElementById('treerow'+row_no).appendChild(c4);
				document.getElementById('treerow'+row_no).appendChild(c5);
			}
			row_no+=1;
			this.row_no= row_no;
		}
}
var p = new Fireice_pref();
